package com.sgb.kjwl.viewmodel.self.carMakers;

import android.app.Application;

import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @author: 黄淋
 * @date: 2021/8/26 16:42
 * @Description: 物流首页菜单viewModel
 */
public class LogisticsMenuFragModel extends AndroidViewModel {
    public MutableLiveData<List<GoodsInfoTypeEntity3>> ldCarType = new MutableLiveData<>();
    public MutableLiveData<List<GoodsInfoTypeEntity3>> ldGoodsType = new MutableLiveData<>();

    public LogisticsMenuFragModel(Application application) {
        super(application);
    }

    /**
     * 获取货源类型
     */
    public void getGoodsType() {
        NewAPIManager.getInstance().getLogisticsAPI().getAllGoodsType().enqueue(new Callback<BaseEntity<List<GoodsInfoTypeEntity3>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<GoodsInfoTypeEntity3>>> call, Response<BaseEntity<List<GoodsInfoTypeEntity3>>> response) {
                if (response.body() == null) return;
                if (response.body().getCode().equals("200") && response.body().getData() != null) {
                    ldGoodsType.postValue(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<GoodsInfoTypeEntity3>>> call, Throwable t) {

            }
        });

    }

    /**
     * 获取车型
     */
    public void getCarTypeList() {
        NewAPIManager.getInstance().getLogisticsAPI().getCarTypeAndLen("").enqueue(new ICallBack<BaseEntity<List<GoodsInfoTypeEntity3>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsInfoTypeEntity3>> data) {
                List<GoodsInfoTypeEntity3> carTypeList = data.getData() != null ? data.getData() : new ArrayList<>();
                //刷新车长与车型
                ldCarType.postValue(carTypeList);
            }
        });
    }

}
